package com.itheima02.thread;

import java.util.concurrent.*;

public class Demo4_Thread {
    /*
        Executor类：提供了一系列工厂方法用于创建线程池，返回的线程池实现了ExecutorService接口。

        public static ExecutorService newFixedThreadPool(int nThread):创建固定数目线程的线程池

        public static ExecutorService newSingleThreadExecutor():创建一个单线程化的Executor

        ExecutorService提供了submit()方法，传递一个Callable，或Runnable，将线程放到池子里，并执行


     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建一个指定线程的线程池
        ExecutorService pool = Executors.newFixedThreadPool(2);

        //将线程放到池子里，并执行
        pool.submit(new RunnableThread2());
        pool.submit(new RunnableThread2());

        //关闭线程池
        pool.shutdown();
    }
}

class RunnableThread2 implements Runnable {

    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }
}
